package com.src.notebookofcy;

import android.os.Environment;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class FileTools
{
  public static final int SORT_TIME = 1;
  public static File documents;
  public static File file = Environment.getExternalStorageDirectory();

  static
  {
    documents = new File(file.getPath() + "/Liunian/documents");
  }

  public FileTools()
  {
    if (documents.exists())
      return;
    createDic(documents);
  }

  public static void deleteFile(File paramFile)
  {
    if (!paramFile.exists())
      return;
    paramFile.delete();
  }

  public static String getFileType(File paramFile)
  {
    String str = paramFile.getName();
    int i = str.lastIndexOf(".");
    if (i != -1)
      return str.substring(i + 1, str.length());
    return "";
  }

  public static List<File> getTextFile(File paramFile)
  {
    File[] arrayOfFile = paramFile.listFiles();
    ArrayList localArrayList = new ArrayList();
    if (arrayOfFile != null);
    for (int i = 0; ; ++i)
    {
      if (i >= arrayOfFile.length)
        return localArrayList;
      if ((!arrayOfFile[i].isFile()) || (!getFileType(arrayOfFile[i]).equalsIgnoreCase("txt")))
        continue;
      localArrayList.add(arrayOfFile[i]);
    }
  }

  public static String getTimeFormat(File paramFile)
  {
    return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA).format(new Date(paramFile.lastModified()));
  }

  public static String openText(File paramFile)
  {
    try
    {
      byte[] arrayOfByte = new byte[1024];
      FileInputStream localFileInputStream = new FileInputStream(paramFile);
      ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
      int i = localFileInputStream.read(arrayOfByte);
      if (i == -1)
        return new String(localByteArrayOutputStream.toByteArray());
      label72: localByteArrayOutputStream.write(arrayOfByte, 0, i);
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      localFileNotFoundException.printStackTrace();
      return "";
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
      break label72;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      break label72;
    }
  }

  public static File[] sortFile(File[] paramArrayOfFile, int paramInt)
  {
    switch (paramInt)
    {
    default:
      return null;
    case 1:
    }
    return sortFileByTime(paramArrayOfFile);
  }

  public static File[] sortFileByTime(File[] paramArrayOfFile)
  {
    int i = 0;
    if (i >= -1 + paramArrayOfFile.length)
      return paramArrayOfFile;
    for (int j = 0; ; ++j)
    {
      if (j >= -1 + paramArrayOfFile.length - i)
        ++i;
      if (paramArrayOfFile[j].lastModified() >= paramArrayOfFile[(j + 1)].lastModified())
        continue;
      File localFile = paramArrayOfFile[j];
      paramArrayOfFile[j] = paramArrayOfFile[(j + 1)];
      paramArrayOfFile[(j + 1)] = localFile;
    }
  }

  public void createDic(File paramFile)
  {
    paramFile.mkdirs();
  }

  public void createFile(File paramFile)
  {
    try
    {
      paramFile.createNewFile();
      return;
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
  }

  public boolean getSdcardState()
  {
    return Environment.getExternalStorageState().equals("mounted");
  }

  public void saveFile(String paramString1, String paramString2)
  {
    File localFile = new File(documents.getPath() + "/" + paramString2 + ".txt");
    createFile(localFile);
    writeFile(paramString1, localFile);
  }

  public void writeFile(String paramString, File paramFile)
  {
    if (!paramFile.exists())
      return;
    try
    {
      new FileOutputStream(paramFile).write(paramString.getBytes());
      return;
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      localFileNotFoundException.printStackTrace();
      return;
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
  }
}

/* Location:           C:\Users\god\Desktop\liunianjishiben_V1.1_mumayi_3745b_dex2jar.jar
 * Qualified Name:     com.src.notebookofcy.FileTools
 * JD-Core Version:    0.5.4
 */